package com.shop.supply.service.impl;



import com.github.pagehelper.PageHelper;
import com.shop.supply.dao.SupplierMapper;
import com.shop.supply.entity.SupplierInfo;
import com.shop.supply.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description：业务逻辑实现类
 * @author：xyj
 * @date：2021/7/20 14:39
 * @versions：v1.0
 */
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;
    /**
     * 添加供货商
     * @param supCode 供货商编码
     * @param supName 供货商名称
     * @param supDesc 供货商描述
     * @param supContact 联系人
     * @param supPhone 联系电话
     * @param supAddress 地址
     * @param supFax 传真
     * @return
     */
    @Override
    public boolean add(String supCode, String supName, String supDesc, String supContact, String supPhone, String supAddress, String supFax,Integer createdUserId, Date createdTime, Date updatedTime, Integer updatedUserId) {
        Integer add = supplierMapper.add(new SupplierInfo(null, supCode, supName, supDesc, supContact, supPhone, supAddress, supFax, createdUserId, new Date(), updatedTime, updatedUserId));
        if(add==1){
            return true;
        }
        return false;
    }
    /**
     * 根据供货商id查询详细信息
     * @param id 供货商id
     * @return
     */
    @Override
    public SupplierInfo getSupplierid(Integer id) {
        return supplierMapper.getSupplierid(id);
    }
    /**
     * 查询供货商详细信息
     * @param pageNo 当前页码
     * @param pageSize 每次查询条数
     * @param supCode 供货商编码
     * @param supName 供货商名称
     * @return
     */
    @Override
    public List<SupplierInfo> getSupplier(Integer pageNo, Integer pageSize, String supCode, String supName) {
        PageHelper.startPage(pageNo, pageSize);
        Map<String,Object>map=new HashMap<>();
        map.put("supCode",supCode);
        map.put("supName",supName);
        return supplierMapper.getSupplier(map);
    }
    /**
     * 根据id删除供货商信息
     * @param id 供货商id
     * @return
     */
    @Override
    public boolean supplierDel(Integer id) {
        Integer integer = supplierMapper.supplierDel(id);
        if (integer==1){
            return true;
        }
        return false;
    }
    /**
     * 修改供货商信息
     * @param id 供货商id
     * @param supCode 供货商编码
     * @param supName 供货商名称
     * @param supDesc 供货商描述
     * @param supContact 联系人
     * @param supPhone 联系电话
     * @param supAddress 地址
     * @param supFax 传真
     * @return
     */
    @Override
    public boolean supplierUpdate(Integer id, String supCode, String supName, String supDesc, String supContact, String supPhone, String supAddress, String supFax) {
        Integer integer = supplierMapper.supplierUpdate(new SupplierInfo(id, supCode, supName, supDesc, supContact, supPhone, supAddress, supFax,null,null,null,null));
        if(integer==1){
            return true;
        }
        return false;
    }
}
